package com.smarttest.portal.controller;

import java.util.ArrayList;
import java.util.List;






import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.g7s.test.utils.common.CommonUtils;
import com.smarttest.common.beans.GeneralResultWithStatus;
import com.smarttest.portal.pojo.DbAutoRelease;
import com.smarttest.portal.service.AutoG7ReportService;

@RequestMapping("/autog7Report")
@Controller
public class AutoG7ReportController {
	@Autowired
	AutoG7ReportService AutoG7ReportService;
	@RequestMapping(value = "/getReports.action", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public GeneralResultWithStatus getReports(int env, int release, String modules,
			String idStr, String importantsStr, String ownersStr,
			String levels, String results, String time) {		
		List<Integer> idlist = JSON.parseArray(idStr, Integer.class);
		List<Integer> importantlist = JSON.parseArray(importantsStr, Integer.class);
		List<String> ownerlist = JSON.parseArray(ownersStr, String.class);
		List<Integer> modulelist = JSON.parseArray(modules, Integer.class);
		List<Integer> levellist = JSON.parseArray(levels, Integer.class);
		List<String> resultlist = JSON.parseArray(results, String.class);
		return GeneralResultWithStatus.okData(null, AutoG7ReportService.GetReports(env, release, modulelist, idlist, importantlist, ownerlist, levellist, resultlist, time));
	}
	@RequestMapping(value = "/getReleases.action", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public GeneralResultWithStatus getReleases(int env) {
		List<DbAutoRelease> l = AutoG7ReportService.getReleases(env);
		String options = "<option value=\"0\" selected=\"selected\">-请选择-</option>";		
		for (DbAutoRelease release : l) {
			options += "<option value=\""+release.getId()+"\">"+release.getName()+"</option>";
		}
		return GeneralResultWithStatus.okData(null, options);
	}
}
